using AutoMapper;
using AdminSystem.API.Models;
using AdminSystem.API.DTOs;

namespace AdminSystem.API.Profiles
{
    public class MappingProfile : Profile
    {
        public MappingProfile()
        {
            // User mappings
            CreateMap<User, UserDto>()
                .ForMember(dest => dest.Roles, opt => opt.MapFrom(src => src.UserRoles.Select(ur => ur.Role)));

            // Role mappings
            CreateMap<Role, RoleDto>()
                .ForMember(dest => dest.Permissions, opt => opt.MapFrom(src => src.RolePermissions.Select(rp => rp.Permission)));

            // Permission mappings
            CreateMap<Permission, PermissionDto>();

            // Module mappings
            CreateMap<Module, ModuleDto>();

            // Content mappings
            CreateMap<Content, ContentDto>()
                .ForMember(dest => dest.AuthorName, opt => opt.MapFrom(src => src.Author.FullName ?? src.Author.Username));
        }
    }
}
